package com.jingan.nursinghome.regulatory.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;

import cn.android.support.v7.lib.sin.crown.base.BaseView;
import cn.android.support.v7.lib.sin.crown.utils.AssetsUtils;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/9/29.
 */

public class liView extends BaseView {
    public liView(Context context) {
        super(context);
        init();
    }

    public liView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    Bitmap bitmap;
    String info;

    public void setLeftAndInfo(String left, String info) {
        if (left != null) {
            bitmap = AssetsUtils.getInstance().getBitmapFromAssets( left, 0, true);
            bitmap = ProportionUtils.getInstance().adapterBitmap(bitmap);
        }
        if (info != null) {
            this.info = info;
        }
        bitmapWidth = bitmap.getWidth();
        textWidth = (int) textPaint.measureText(info, 0, info.length());
        width = bitmapWidth + textWidth + intervalWidth;
        height = TextSize > bitmap.getHeight() ? TextSize : bitmap.getHeight();
        height=height+ProportionUtils.getInstance().adapterInt(10);
        requestLayout();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(width, height);
    }

    int width, height;
    int bitmapWidth, textWidth, intervalWidth = ProportionUtils.getInstance().adapterInt(27);

    private void init() {
        setMainOrSub(true);
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        canvas.drawBitmap(bitmap, 0, getHeight() - bitmap.getHeight(), paint);
        textPaint.setTextAlign(Paint.Align.LEFT);
        canvas.drawText(info, bitmapWidth + intervalWidth, (float) (height*0.9), textPaint);
    }
}
